import { wordCountAndSort } from '@/lib/utils';
import { responseOk } from '@/server/apiResponse';
import { getClsArticles } from '@/server/controllers/articleController';
import { getBriefs } from '@/server/controllers/briefController';
import { tokenize } from '@/server/controllers/jiebaController';
import { Hono } from 'hono';

export const secuRoutes = new Hono()
    .get('/brief/:secu_code', async (c) => {
        const { secu_code } = c.req.param();
        const briefs = await getBriefs(secu_code);
        return c.json(responseOk(briefs));
    })
    .get('/news/hotkeys', async (c) => {
        const articles = await getClsArticles();
        articles.map((art) => {
            const tokens = tokenize(art.art_title);
            art.tokens = tokens;
        });
        const allTokens = articles.map((a) => {
            return a.tokens;
        });
        const hotKeys = wordCountAndSort(allTokens);
        // const hotKeys = Object.keys(commonWords);
        return c.json(responseOk(hotKeys));
    });
